package com.jm.offer.easy;

import com.jm.offer.TreeNode;
import sun.reflect.generics.tree.Tree;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @Description https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof/
 * @date 2022/4/17 13:03
 */
public class _27二叉树的镜像 {

    public static void main(String[] args) {

    }

    public static TreeNode mirrorTree(TreeNode root) {
        if (root == null){
            return root;
        }

        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);

        while (!queue.isEmpty()){
            TreeNode node = queue.poll();

            TreeNode tmp = node.left;
            node.left = node.right;
            node.right = tmp;

            if (node.left != null){
                queue.offer(node.left);
            }

            if (node.right != null){
                queue.offer(node.right);
            }

        }
        return root;
    }

}
